package com.upb.webserver.dao.mapper;

import com.upb.webserver.dao.entity.TbToken;
import com.upb.webserver.dao.entity.TbTokenExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import java.util.List;
import java.util.Optional;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.annotations.SelectKey;

public interface TbTokenMapper {

    @Delete({ "delete from tb_token", "where expire_time < now()" })
    int removeExpireToken();

    @Delete({ "delete from tb_token", "where value = #{value,jdbcType=VARCHAR}" })
    int deleteByValue(@Param("value") String value);

    @Delete({ "delete from tb_token", "where token = #{token,jdbcType=VARCHAR}" })
    int deleteByToken(@Param("token") String token);

    @Select({ "select", TbTokenSqlProvider.ALL_COLUMN_FIELDS, "from tb_token", "where token = #{token,jdbcType=VARCHAR}" })
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "token", property = "token", jdbcType = JdbcType.VARCHAR), @Result(column = "value", property = "value", jdbcType = JdbcType.VARCHAR), @Result(column = "expire_time", property = "expireTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP) })
    TbToken selectByToken(@Param("token") String token);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_token
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbTokenSqlProvider.class, method = "countByExample")
    long countByExample(TbTokenExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_token
     *
     * @mbg.generated
     */
    @DeleteProvider(type = TbTokenSqlProvider.class, method = "deleteByExample")
    int deleteByExample(TbTokenExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_token
     *
     * @mbg.generated
     */
    @Delete({ "delete from tb_token", "where id = #{id,jdbcType=INTEGER}" })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_token
     *
     * @mbg.generated
     */
    @Insert({ "insert into tb_token (token, value, ", "expire_time, create_time)", "values (#{token,jdbcType=VARCHAR}, #{value,jdbcType=VARCHAR}, ", "#{expireTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP})" })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insert(TbToken record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_token
     *
     * @mbg.generated
     */
    @InsertProvider(type = TbTokenSqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insertSelective(TbToken record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_token
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbTokenSqlProvider.class, method = "selectByExample")
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "token", property = "token", jdbcType = JdbcType.VARCHAR), @Result(column = "value", property = "value", jdbcType = JdbcType.VARCHAR), @Result(column = "expire_time", property = "expireTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP) })
    List<TbToken> selectByExample(TbTokenExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_token
     *
     * @mbg.generated
     */
    @Select({ "select", "id, token, value, expire_time, create_time", "from tb_token", "where id = #{id,jdbcType=INTEGER}" })
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "token", property = "token", jdbcType = JdbcType.VARCHAR), @Result(column = "value", property = "value", jdbcType = JdbcType.VARCHAR), @Result(column = "expire_time", property = "expireTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP) })
    TbToken selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_token
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbTokenSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") TbToken record, @Param("example") TbTokenExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_token
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbTokenSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") TbToken record, @Param("example") TbTokenExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_token
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbTokenSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(TbToken record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_token
     *
     * @mbg.generated
     */
    @Update({ "update tb_token", "set token = #{token,jdbcType=VARCHAR},", "value = #{value,jdbcType=VARCHAR},", "expire_time = #{expireTime,jdbcType=TIMESTAMP},", "create_time = #{createTime,jdbcType=TIMESTAMP}", "where id = #{id,jdbcType=INTEGER}" })
    int updateByPrimaryKey(TbToken record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_token
     *
     * @mbg.generated
     */
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert({ "<script>", "insert into tb_token (token, ", "value, expire_time, ", "create_time)", "values<foreach collection=\"list\" item=\"detail\" index=\"index\" separator=\",\">(#{detail.token,jdbcType=VARCHAR}, ", "#{detail.value,jdbcType=VARCHAR}, #{detail.expireTime,jdbcType=TIMESTAMP}, ", "#{detail.createTime,jdbcType=TIMESTAMP})</foreach></script>" })
    int batchInsert(List<TbToken> list);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_token
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbTokenSqlProvider.class, method = "getOneByExample")
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "token", property = "token", jdbcType = JdbcType.VARCHAR), @Result(column = "value", property = "value", jdbcType = JdbcType.VARCHAR), @Result(column = "expire_time", property = "expireTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP) })
    Optional<TbToken> getOneByExample(TbTokenExample example);
}
